package 力扣._36有效的数独;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

class Solution {
    public boolean isValidSudoku(char[][] board) {
        List<Set<Integer>> rowSetList = new ArrayList<>(9);
        List<Set<Integer>> colSetList = new ArrayList<>(9);
        List<Set<Integer>> blockSetList = new ArrayList<>(9);

        for (int i = 0; i < 9; i++) {
            rowSetList.add(new HashSet<>());
            colSetList.add(new HashSet<>());
            blockSetList.add(new HashSet<>());
        }

        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if(board[i][j]=='.')
                    continue;
                int t = board[i][j] - '0';
                if(rowSetList.get(i).contains(t))
                    return false;
                if(colSetList.get(j).contains(t))
                    return false;
                // 块的下标
                int idx = i/3 * 3 + j/3;
                System.out.printf("%d %d->%d\n", i,j, idx);
                if(blockSetList.get(idx).contains(t))
                    return false;
                rowSetList.get(i).add(t);
                colSetList.get(j).add(t);
                blockSetList.get(idx).add(t);

            }
        }
        return true;

    }
}